/*
题目链接:https://leetcode.cn/problems/count-number-of-bad-pairs/description/?envType=daily-question&envId=2025-04-18
*/

//题解代码:
class Solution {
public:
    #define ll long long
    long long countBadPairs(vector<int>& nums) {
        int n = nums.size();
        for(int i=0;i<n;++i) nums[i] -= i;
        ll ans = 1LL*n*(n-1)/2;
        unordered_map<int,int> ump;
        for(int i=0;i<n;++i){
            ans -= ump[nums[i]];
            ump[nums[i]]++;
        }
        return ans;        
    }
};
